// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
// import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
// import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatement;
// import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
// import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;
#include "SQLServerUpdateStatement.h"
#include "../../../../../DbType.h"
#include "../SQLServerOutput.h"
#include "../SQLServerTop.h"
#include "../../visitor/SQLServerASTVisitor.h"
#include "../../../../visitor/SQLASTVisitor.h"
#include "../../../../ast/statement/SQLTableSource.h"
#include "../../../../ast/statement/SQLUpdateSetItem.h"
#include "../../../../../utils/listTran.h"

SQLServerUpdateStatement::SQLServerUpdateStatement()
    : SQLUpdateStatement(DbType_ptr(new DbType(&DbType::sqlserver)))
{
}

SQLServerTop_ptr SQLServerUpdateStatement::getTop()
{
  return top;
}

void SQLServerUpdateStatement::setTop(SQLServerTop_ptr top)
{
  if (top != nullptr)
  {
    top->setParent(SharedObject(SQLServerUpdateStatement));
  }
  this->top = top;
}

SQLServerOutput_ptr SQLServerUpdateStatement::getOutput()
{
  return output;
}

void SQLServerUpdateStatement::setOutput(SQLServerOutput_ptr output)
{
  if (output != nullptr)
  {
    output->setParent(SharedObject(SQLServerUpdateStatement));
  }
  this->output = output;
}

// @Override
void SQLServerUpdateStatement::accept0(SQLASTVisitor_ptr visitor)
{
  this->accept0(std::dynamic_pointer_cast<SQLServerASTVisitor>(visitor));
}

// @Override
void SQLServerUpdateStatement::accept0(SQLServerASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLServerUpdateStatement)))
  {
    SQLObjectImpl::acceptChild(visitor, top);
    SQLObjectImpl::acceptChild(visitor, tableSource);
    SQLObject_list_ptr tmp = ListTran::tran_class<SQLUpdateSetItem, SQLObject>(items);
    SQLObjectImpl::acceptChild(visitor, tmp);
    SQLObjectImpl::acceptChild(visitor, output);
    SQLObjectImpl::acceptChild(visitor, from);
    SQLObjectImpl::acceptChild(visitor, where);
  }
  visitor->endVisit(SharedObject(SQLServerUpdateStatement));
}
